<template>
  <div>

    <el-card class="box-card">
      <div>
        <el-form label-width="80px"
                 class="form-control">

          <el-form-item class="sercheItem">
            <!-- <el-input></el-input> -->

            <el-row type="flex"
                    :gutter="4"
                    align="middle">

              <el-col :span="1.5">
                <el-button size="small"
                           type="primary"
                           icon="el-icon-search"
                           @click="search">搜索</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button icon='el-icon-refresh'
                           size="small">重置</el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </el-form>
      </div>
      <el-table :data="tableData"
                style="width: 100%"
                :header-cell-style="{background:'#f8f8f9','text-align':'center'}"
                :cell-style="{'text-align':'center'}">
        <el-table-column type="selection">
        </el-table-column>
        <el-table-column prop="id"
                         label="帮我约她关联id">
        </el-table-column>
        <el-table-column prop="createTime"
                         label="添加时间">
        </el-table-column>
        <el-table-column prop="remark"
                         label="备注">

        </el-table-column>

        <el-table-column prop="uid"
                         label="用户id">
        </el-table-column>
        <el-table-column prop="u.nickName"
                         label="用户昵称">
        </el-table-column>
        <el-table-column prop="u.phone"
                         label="用户电话">
        </el-table-column>
        <el-table-column prop="fid"
                         label="好友id">
        </el-table-column>
        <el-table-column prop="f.nickName"
                         label="好友昵称">
        </el-table-column>
        <el-table-column prop="f.phone"
                         label="好友电话">
        </el-table-column>
        <el-table-column label="操作">
          <template v-slot="data">
            <el-button icon="el-icon-delete"
                       type="text"
                       @click="deleteHandler(data.row.id)">删除</el-button>
            <el-button icon="el-icon-delete"
                       type="text"
                       @click="updateHandler(data.row.id)">修改</el-button>
          </template>

        </el-table-column>
      </el-table>
      <div class="page"
           v-show="total!=0">
        <el-pagination background
                       @size-change="handleSizeChange"
                       @current-change="handleCurrentChange"
                       :current-page="queryData.pageNum"
                       :page-sizes="[3, 5, 7, 9]"
                       :page-size="queryData.pageSize"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="total">
        </el-pagination>
      </div>
    </el-card>
    <div>
      <el-dialog title="修改帮我约她关联i"
                 :visible.sync="dialogVisible"
                 width="30%">
        <el-form :model="formData"
                 label-width="80px">
          <el-form-item label="备注">
            <el-input v-model="formData.remark"
                      placeholder="请输入备注名称"></el-input>
          </el-form-item>

        </el-form>
        <span slot="footer"
              class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary"
                     @click="addXqqType">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      queryData: {
        pageNum: 1,
        pageSize: 5
      },
      loading: false,
      tableData: [],
      total: 0,
      dialogVisible: false,
      formData: { createBy: null, createTime: null, f: null, fid: null, id: null, params: {}, remark: null, searchValue: null, u: null, uid: null, updateBy: null, updateTime: null }
    }
  },
  mounted() {
    this.getDate()
  },
  methods: {
    async getDate() {
      this.loading = true
      let { data } = await this.$axios.get('com/yt/list', { params: this.queryData })
      console.log(data)
      this.tableData = data.rows
      this.total = data.total
      this.loading = false
    },
    handleSizeChange(val) {
      this.queryData.pageSize = val
      this.getDate()
    },
    handleCurrentChange(val) {
      this.queryData.pageNum = val
      this.getDate()
    },
    search() {
      this.getDate()
    },

    async updateHandler(id) {
      this.dialogVisible = true
      let { data } = await this.$axios.get(`com/yt/${id}`)

      this.formData = data.data
    },
    deleteHandler(id) {
      this.$confirm(`是否确认删除名字编号为${id.toString()}的数据项?`, '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          let { data } = await this.$axios.delete(`com/yt/${id.toString()}`)
          console.log(data)
          if (data.code != 200) this.$message.error(data.msg)
          this.$message({
            type: 'success',
            message: data.msg
          })
          this.getTableList()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    async addXqqType() {
      let { data } = await this.$axios.put(`com/yt/`, this.formData)
      if (data.code != 200) return this.$message.error(data.msg)
      this.$message({ type: 'success', message: data.msg })
      this.getDate()
      this.dialogVisible = false
    }
  }
}
</script>

<style lang="scss" scoped>
.form-control {
  display: flex;
}
.page {
  margin-top: 15px;
  display: flex;
  justify-content: flex-end;
}
</style>